package com.sesame.user.controller;

import com.sesame.user.bean.User;
import com.sesame.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import kim.sesame.common.web.controller.AbstractWebController;
import kim.sesame.common.result.ApiResult;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * UserController
 *
 * @author admin
 * @date 2019-01-30 13:03:18
 * @Description:
 */
@Api(description = "用户接口")
@CommonsLog
@RestController
@RequestMapping("/user")
public class UserController extends AbstractWebController {

    @Resource
    private UserService userService;

    /**
     * 查询list
     *
     * @author admin
     * @date 2019-01-30 13:03:18
     * @Description:
     */
    @ApiOperation(value = "获取用户列表", notes = "xxxxxxxxxxxxxxxx")
    @GetMapping("/list")
    public ApiResult list() {

        List<User> list = userService.searchList();

        return success(list);
    }

    /**
     * 保存
     *
     * @author admin
     * @date 2019-01-30 13:03:18
     * @Description:
     */
    @ApiOperation(value = "修改用户", notes = "根据User对象创建用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "updateUser", value = "修改人", required = true, dataType = "String")
    })
    @GetMapping("/save")
    public ApiResult save(String updateUser) {
        User bean = new User();
        bean.setId("1");
        bean.initUpdate(updateUser);
        int res = userService.update(bean);
        return success(res);
    }


}
